package com.chen.model;

import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.chen.services.EclassService;
import com.chen.services.EclassServiceImpl;

@Controller
@RequestMapping()
public class EclassController {

	private List<Eclass> Eclasses = new ArrayList<Eclass>();
	private EclassService eclassService = new EclassServiceImpl();
	
	@RequestMapping(method=RequestMethod.GET)
	public String getEclassquery(Model model) {
		model.addAttribute(new Eclass());
		return "eclassquery";
	}
	
	@RequestMapping(value="/eclass",method=RequestMethod.POST)
	public String create(@Valid Eclass eclass, BindingResult result) {
		if (result.hasErrors()) {
			return "eclasscreate";
		}
		System.out.println("*************************"+eclass.getClassID());
		
		return "eclassview";

	}
	
	@RequestMapping(value="/query", method=RequestMethod.GET)
	public String query(@Valid Eclass eclass, Model model) throws Exception {
		Eclasses.clear();
		Eclasses = eclassService.getEclass();
/*		Eclass ec = new Eclass();
		ec.setClassID("z");
		Eclasses.add(ec);*/
		model.addAttribute("Eclasses",Eclasses);
		return "eclassview";

	}
	

}
